// 随手使用的测试类

var express = require('express');
var app = express();
var http = require('http');
var users = new Array();

http.createServer(app).listen(8080, function() {
    console.log('http server started successfully,at port 8080.');
});
var count = 0

app.get("*", function (req, res,next){
    console.log("income visit. the " + ++count )
    next()
})

// 一次访问 5秒以后才做出回应.
app.get('/', function (req, res) {
    var now = new Date().getTime()  // 毫秒

    setTimeout(function(){
        var time = new Date().getTime() - now
        console.log("send back. "+time)
        res.send('local server tell you: Hello.');
    },5000)
});


app.get('/json', function (req, res) {
    var now = new Date().getTime()  // 毫秒
    var json = {}
    json.name = 'haha'
    json.date = now
    json.childs = ['xiao1','xiao2',97,63]
    res.json(json);
});

app.get('/login', function (req, res) {
    var now = new Date().getTime()  // 毫秒
    var json = {}
    json.token = "" + now + Math.random(1000)
    json.status = 0
    var user = {
        token : json.token,
    }
    users.push(user)
    res.json(json);
});


